<template>
	<view class="mask">
		<u-popup v-model="regBool"  mode="center" :mask-close-able="false">
			<view class="mwrap">
				<image class="renge" mode="widthFix" :src="imgPath+'/static/big/teamCenter/shouquan.png'"></image>
				<view class="confirm" @click="confirm"></view>
			</view>
		</u-popup>
		
	</view>
</template>
<script>
	import http from "@/src/http";
	export default {
		name:"Shouquan",
		props:{
			config:{
				type: Object,
				default: () => {}
			}
		},
		data() {
			return {
				regBool:false,
				trueConfig: {}
			};
		},
		watch: { // 监听到数据然后赋值
      config:{
        // 监听数据发生变化的处理函数
        handler(newV) {
          this.trueConfig = JSON.parse(JSON.stringify(newV));//将监听到修改的值赋予到dataAttrs中
        },
        // 是否开启深度监听，由于我们上面props中是一个Object对象，所以需要开启深度监听功能
        deep: true
      }
    },
		mounted() {
			this.trueConfig= this.config; //用props中的对象对data中的对象赋初始值
		},
		methods:{
			confirm(){
				//this.regBool = false;
				let that = this;
				console.log(111, this.trueConfig)
				let mbtiTmpIds = this.trueConfig.mbtiTmpIds;
				let tmplIds = Object.values(mbtiTmpIds);
				wx.requestSubscribeMessage({
					tmplIds: tmplIds,
					success(res) {
						let accepts = [];
						console.info('获取订阅消息：',res);
						Object.keys(mbtiTmpIds).forEach(key=>{
							if(res[mbtiTmpIds[key]]=='accept'){
								accepts.push(key)
							}
						})
						if(accepts.length>0){
							http.subscribe({type:accepts}).then(res2=>{
								uni.showToast({
									title:res2.message
								});
							});
						}else{
							wx.showModal({
								title: '提示',
								content: '订阅失败，可在小程序设置中开启该消息订阅通知'
							})
						}
					},
					fail(res) {
						wx.showModal({
							title: '提示',
							content: '订阅失败，可在小程序设置中开启该消息订阅通知'
						})
					}
				})
				this.wait();
				//this.$emit('success');
			},
			wait(){
				this.regBool = false
			},
			show(){
				this.regBool = true
			}
		}
	}
</script>

<style lang="less" scoped>

.mwrap{
	width: 750rpx;
	display: flex;
	justify-content: center;
	position: relative;
	.renge{
		width: 605rpx;
		position: relative;
	}
	.confirm{
		position: absolute;
		width: 180rpx;
		height: 80rpx;
		right: 300rpx;
		border-radius: 40rpx;
		bottom: 0;
	}
}

</style>